<template>
  <div>
    <page-header-wrapper>
      <application-search @search="handleSearch" @reset="handleReset"></application-search>
      <a-card :bordered="false">
        <div class="table-header m-b-24"></div>
        <s-table
          ref="table"
          size="default"
          :rowKey="(record, index) => index"
          :changeExportQuery="true"
          :columns="columns"
          :data="loadData"
          :dataT="loadDataT"
          :dataG="loadDataG"
          :dataL="loadDataL"
          :scroll="{ x: true }"
        >
          <div slot="tabAction">
            <buttonSelect
              v-model="typeSelect"
              :options="[
                { value: '', label: '全部' },
                { value: '变更', label: '变更' },
                { value: '退出', label: '退出' },
                { value: '其他', label: '历史数据' },
                // { value: '2', label: '已接收' },
                // { value: '-1', label: '已退回' },
              ]"
              @change="tableRefresh(true)"
            ></buttonSelect>
          </div>
          <Ellipsis :length="18" tooltip slot="changeReason" slot-scope="text" class="text-warning">
            {{ text }}
          </Ellipsis>
          <span slot="districtResult" slot-scope="text" :class="textColor(text)">{{
            stateText(text, 'district')
          }}</span>
          <span slot="cityResult" slot-scope="text" :class="textColor(text)">{{ stateText(text, 'city') }}</span>
          <span slot="YdData" slot-scope="text">{{ text | moment('YYYY-MM-DD') }}</span>
          <span slot="QjOperatTime" slot-scope="text">
            <span v-if="text.startsWith('0001')"></span>
            <span v-else>{{ text | moment('YYYY-MM-DD') }}</span></span
          >
          <span slot="SjOperatTime" slot-scope="text"
            ><span v-if="text.startsWith('0001')"></span> <span v-else>{{ text | moment('YYYY-MM-DD') }}</span></span
          >
        </s-table>
      </a-card>
    </page-header-wrapper>
    <declare :data.sync="recordData" :visible.sync="visibleDeclare" />
  </div>
</template>

<script>
import { STable, Ellipsis, buttonSelect, applicationSearch } from '@/components'
import declare from './components/declare.vue'
import { getYdsbResult } from '@/api/communityReviewManagement'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
    buttonSelect,
    declare,
    applicationSearch,
  },
  computed: {
    textColor() {
      return function (text) {
        const classMap = new Map([
          ['-1', 'text-warning'],
          ['1', 'text-error'],
          ['0', 'text-success'],
        ])
        return classMap.get(text)
      }
    },
    stateText() {
      return function (state, type) {
        if (type === 'city') {
          const cityMap = new Map([
            ['-1', '待审核'],
            ['1', '作废'],
            ['0', '执行'],
          ])
          return cityMap.get(state)
        }
        if (type === 'district') {
          const districtMap = new Map([
            ['-1', '待审核'],
            ['1', '作废'],
            ['0', '同意申报'],
          ])
          return districtMap.get(state)
        }
        return ''
      }
    },
  },
  data() {
    return {
      typeSelect: '',
      visibleDeclare: false,
      recordData: {},
      queryParam: {
        DeptID: this.$store.getters.userInfo.DeptID,
        strContent: {},
      },
      queryParamT: {
        DeptID: this.$store.getters.userInfo.DeptID,
        strContent: {
          YDLX: '退出',
        },
      },
      queryParamG: {
        DeptID: this.$store.getters.userInfo.DeptID,
        strContent: {
          YDLX: '变更',
        },
      },
      queryParamL: {
        DeptID: this.$store.getters.userInfo.DeptID,
        strContent: {
          YDLX: '其他',
        },
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 80,
          customRender: (text, record, index) => <span>{index + 1}</span>,
        },
        {
          title: '申请编号',
          align: 'center',
          dataIndex: 'ApplyNo',
          width: 140,
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'Proposer',
          width: 140,
        },
        {
          title: '身份证号',
          align: 'center',
          dataIndex: 'IDCard',
          width: 180,
        },
        {
          title: '异动类型',
          align: 'center',
          dataIndex: 'YDLX',
        },
        {
          title: '现保障人口',
          align: 'center',
          dataIndex: 'XBZRK',
        },
        {
          title: '现人均住房面积',
          align: 'center',
          dataIndex: 'XRJZFMJ',
        },
        {
          title: '异动原因',
          align: 'center',
          dataIndex: 'YdReason',
          width: 180,
          scopedSlots: { customRender: 'changeReason' },
        },
        {
          title: '异动时间',
          align: 'center',
          dataIndex: 'YdData',
          scopedSlots: { customRender: 'YdData' },
          width: 140,
        },
        {
          title: '经办人',
          align: 'center',
          dataIndex: 'Agent',
          width: 140,
        },
        {
          title: '区级审核日期',
          align: 'center',
          dataIndex: 'QjOperatTime',
          scopedSlots: { customRender: 'QjOperatTime' },
          width: 140,
        },
        {
          title: '市(级)审批日期',
          align: 'center',
          dataIndex: 'SjOperatTime',
          scopedSlots: { customRender: 'SjOperatTime' },
          width: 140,
        },
        {
          title: '区级审核状态',
          align: 'center',
          fixed: 'right',
          dataIndex: 'QjState',
          scopedSlots: { customRender: 'districtResult' },
          width: 140,
        },
        {
          title: '市(级)审批',
          align: 'center',
          fixed: 'right',
          dataIndex: 'SjState',
          scopedSlots: { customRender: 'cityResult' },
          width: 140,
        },
        {
          title: '操作',
          align: 'center',
          width: 160,
          fixed: 'right',
          customRender: (text, record, index) => {
            // 市级审核日期小于15天
            // if (moment().diff(moment(record.CityRfyDate), 'days') <= 15) {
            //   return (
            //     <a-tooltip>
            //       <template slot="title">公示期未满，不可异动</template>
            //       <a-icon type="lock" class="text-error" />
            //     </a-tooltip>
            //   )
            // }
            // const { QjState, SjState } = record
            // if (QjState === '0') {
            //   // 市级
            //   if (SjState === '-1') {
            //     return <span class="text-warning">等待市级审核</span>
            //   }
            return (
              <y-button type="link" onclick={this.handleAudit.bind(this, record)}>
                异动修改
              </y-button>
            )
            //   } else {
            //     return (
            //       <y-button type="link" onclick={this.handleAudit.bind(this, record)}>
            //         {/* {QjState !== '-1' ? '异动申报' : '异动修改'} */}
            //         异动修改
            //       </y-button>
            //     )
            //   }
          },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        requestParameters.strContent.YDLX = this.typeSelect
        return getYdsbResult(requestParameters).then((res) => res)
      },
      loadDataT: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParamT)
        return getYdsbResult(requestParameters).then((res) => res)
      },
      loadDataG: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParamG)
        return getYdsbResult(requestParameters).then((res) => res)
      },
      loadDataL: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParamL)
        // requestParameters.strContent.YDLX = this.typeSelect
        return getYdsbResult(requestParameters).then((res) => res)
      },
    }
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      this.tableRefresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.typeSelect = ''
      this.tableRefresh(true)
    },
    tableRefresh(refresh = false) {
      this.$refs.table.refresh(refresh)
    },
    handleAudit(record) {
      this.visibleDeclare = true
      this.recordData = record
    },
  },
}
</script>
<style lang="less" scoped>
.table-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
</style>
